# coding=utf-8
'''
Created on 2012-8-26

@author: quanwei
'''
import threading
import traceback  

class Worker(threading.Thread):
    dispatcher = None
    run = True
    def __init__(self,name,dispatcher):
        threading.Thread.__init__(self, name = name)
        self.dispatcher = dispatcher
        
    #工作线程主方法
    def run(self):        
        while self.run:
            try:
                task = self.dispatcher.getTaskQueue().get(True,1)
            except:
                print "empty queue"
                task = None 
                     
            if task == None:
                continue         
            try:
                self.execute(task)
            except:
                print traceback.format_exc()

        
    #执行一次任务
    def execute(self,task):
        #print("Worker '" + self.name + "' Execute Task")
        pass
    
        